<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="基地" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sourceBase']" placeholder="请输入基地"></a-input>
        </a-form-item>
        <a-form-item label="地块" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sourceGreenhouse']" placeholder="请输入地块"></a-input>
        </a-form-item>
        <a-form-item label="采收产品" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['variety', validatorRules.variety]" placeholder="请输入采收产品"></a-input>
        </a-form-item>
        <a-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['varietyCode', validatorRules.varietyCode]" placeholder="请输入产品编码"></a-input>
        </a-form-item>
        <a-form-item label="打包规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['packingSpecifications', validatorRules.packingSpecifications]" placeholder="请输入打包规格"></a-input>
        </a-form-item>
        <a-form-item label="等级" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['classes', validatorRules.classes]" placeholder="请输入等级"></a-input>
        </a-form-item>
        <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['flowerPoleLength', validatorRules.flowerPoleLength]" placeholder="请输入单位"></a-input>
        </a-form-item>
        <a-form-item label="分拣员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sorter']" placeholder="请输入分拣员"></a-input>
        </a-form-item>
        <a-form-item label="分拣日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择分拣日期" v-decorator="['sortTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="创建日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择创建日期" v-decorator="['createTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择更新日期" v-decorator="['updateTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['createUser']" placeholder="请输入创建人"></a-input>
        </a-form-item>
        <a-form-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['updateUser']" placeholder="请输入更新人"></a-input>
        </a-form-item>
        <a-form-item label="状态( 预出库(1),已出库(2)，损耗3，已删除9)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['state', validatorRules.state]" placeholder="请输入状态( 预出库(1),已出库(2)，损耗3，已删除9)" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="出库时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择出库时间" v-decorator="['stockInTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="入库时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择入库时间" v-decorator="['stockOutTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="入库人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['stockInUser']" placeholder="请输入入库人"></a-input>
        </a-form-item>
        <a-form-item label="出库人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['stockOutUser']" placeholder="请输入出库人"></a-input>
        </a-form-item>
        <a-form-item label="入库表id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inId']" placeholder="请输入入库表id"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'


  export default {
    name: "FlowerTagpreModal",
    components: {
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          variety: {
            rules: [
              { required: true, message: '请输入采收产品!'},
            ]
          },
          varietyCode: {
            rules: [
              { required: true, message: '请输入产品编码!'},
            ]
          },
          packingSpecifications: {
            rules: [
              { required: true, message: '请输入打包规格!'},
            ]
          },
          classes: {
            rules: [
              { required: true, message: '请输入等级!'},
            ]
          },
          flowerPoleLength: {
            rules: [
              { required: true, message: '请输入单位!'},
            ]
          },
          state: {
            rules: [
              { required: true, message: '请输入状态( 预出库(1),已出库(2)，损耗3，已删除9)!'},
            ]
          },
        },
        url: {
          add: "/flower/flowerTagpre/add",
          edit: "/flower/flowerTagpre/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'sourceBase','sourceGreenhouse','variety','varietyCode','packingSpecifications','classes','flowerPoleLength','sorter','sortTime','createTime','updateTime','createUser','updateUser','state','stockInTime','stockOutTime','stockInUser','stockOutUser','inId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'sourceBase','sourceGreenhouse','variety','varietyCode','packingSpecifications','classes','flowerPoleLength','sorter','sortTime','createTime','updateTime','createUser','updateUser','state','stockInTime','stockOutTime','stockInUser','stockOutUser','inId'))
      },


    }
  }
</script>